<template>
  <view>
    <swiper :indicator-dots="true" :autoplay="true" :interval="3000" :duration="1500" indicator-dots>
      <swiper-item v-for="(item,index) in swiperList" :key="index">
        <navigator class="swiper-item" :url="`/subpkg/goods_detail/goods_detail?goods_id=${item.goods_id}`">
          <image :src="item.image_src" mode="widthFix"></image>
        </navigator>
      </swiper-item>
    </swiper>
    
    <view class="nav-list">
    	<view class="nav-item" v-for="(item,index) in navList" :key="index" @click="navClickHandler(item)">
    		<image :src="item.image_src"></image>
    	</view>
    </view>
    
    <view class="floor-list">
      <view class="floor-item" v-for="(item,index) in floorList" :key="index">
        <image class="floor-title" :src="item.floor_title.image_src" mode=""></image>
        <view class="floor-img-box">
          <view class="left-img-box">
            <image :src="item.product_list[0].image_src" mode="widthFix" :style="{width: item.product_list[0].image_width+'rpx'}"></image>
          </view>
          <view class="right-img-box" >
            <view class="right-img-item" v-for="(item2,index2) in item.product_list" :key="index2" v-if="index2>0" >
              <image  :src="item2.image_src" mode="widthFix" :style="{width: item.product_list[0].image_width+'rpx'}"></image >
            </view>
          </view>
        </view>
      </view>
    </view>
  </view>
</template>

<script>
  export default {
    name: 'homePage',
    components:{
    },
    data() {
      return {
        swiperList:[],
        navList:[],
        floorList:[]
      };
    },
    created(){
    },
    mounted(){
    },
    onLoad() {
      this.getSwiperList()
      this.getNavList()
      this.getFloorList()
    },
    methods:{
     async getSwiperList(){
        let {data:{message,meta:{status}}} = await uni.$http.get('/api/public/v1/home/swiperdata')
        if(status!==200){
          return uni.$showMsg()
        }
        this.swiperList = message
      },
      async getNavList(){
        let {data:{message,meta:{status}}}  = await uni.$http.get('/api/public/v1/home/catitems')
        if(status!==200){
          return uni.$showMsg()
        }
        this.navList = message
      },
      async getFloorList(){
        let {data:{message,meta:{status}}}  = await uni.$http.get('/api/public/v1/home/floordata')
        if(status!==200){
          return uni.$showMsg()
        }
        this.floorList = message
      },
      navClickHandler(item){
        if(item.name === '分类'){
          uni.switchTab({
            url:"/pages/cate/cate"
          })
        }
      }
    }
  }
</script>

<style lang="scss">
  swiper {
    height: 330rpx;
    .swiper-item ,image{
      height: 100%;
      width: 100%;
    }
  }
  .nav-list{
    display: flex;
    justify-content: space-around;
    margin: 15px 0;
  }
  .nav-item {
    image{
      width: 128rpx;
      height: 140rpx;
    }
  }
  .floor-title{
    height: 60rpx;
    width: 100%;
    display: flex;
  }
  .floor-img-box{  
    display: flex;
  }
  .right-img-box{
    display: flex;
    flex-wrap: wrap;
    justify-content: space-around;
  } 
  // .right-img-item image {
  //   width: 100%;
  //   height: 100%;
  // }
  
  </style>
